// 双指针法
// 走 a + nb 步一定是在环入口
// 第一次相遇时慢指针已经 nb 步
var detectCycle = function (head) {
  let fast = head,
    slow = head;
  while (true) {
    if (!fast || !fast.next) return null;
    fast = fast.next.next;
    slow = slow.next;
    if (fast == slow) break;
  }
  fast = head;
  while (slow != fast) {
    slow = slow.next;
    fast = fast.next;
  }
  return fast;
};
